<?php
class DiplomaActController  extends Zone_Action{
	public function indexAction(){
		return $this->setJSON(array(
				alert => error("here")
			));
	}

	public function deleteAction(){
		$ids = $_POST["ID"];
		$user_id = get_user_id();
		if(empty($ids)==true){
			return $this->setJSON(array(
				alert => error("Chưa công văn nào được chọn.")
			));
		}
		if(is_array($ids)==true){
			foreach($ids as $id){
				$this->Model->delete("diplomas_users","`diploma_id`='$id'");
				$files = $this->Model->fetchAll("SELECT * FROM `diplomas_files` WHERE `diploma_id`='$id'");
				foreach($files as $k=>$v){
					@unlink("files/diploma/".$v['name']);
				}
				$this->Model->delete("diplomas_files","`diploma_id`='$id'");
				$this->Model->delete("diplomas","`ID` = '$id'");
			}
			
			return $this->setJSON(array(
				redirect => "#Diploma/"
			));
		}
	}
	
}	